﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class PlayerUI : MonoBehaviour
{
    const string text = "Text";
    const string floatFormat1 = "f1";
    const string floatFormat2 = "f2";

    public RectTransform MassLT, SpeedZLT, SpeedYLT, CurrentTypeLT;


    public float UpdateMessageTimeSpan = 0.2f;
    public string[] TypeText;

    new Rigidbody2D rigidbody2D;
    BallUserController buc;
    Ball ball;
    float updateMessTimer = 0f;
    Vector2 minSize_PlayerMessageBox;

    Text massText, speedZText, speedYText, currentTypeText;

    private void Awake()
    {
        rigidbody2D = GetComponent<Rigidbody2D>();
        buc = GetComponent<BallUserController>();
        ball = GetComponent<Ball>();

        massText = MassLT.Find(text).GetComponent<Text>();
        speedZText = SpeedZLT.Find(text).GetComponent<Text>();
        currentTypeText = CurrentTypeLT.Find(text).GetComponent<Text>();
        speedYText = SpeedYLT.Find(text).GetComponent<Text>();
    }
    private void Update()
    {
        updateMessTimer += Time.deltaTime;
        if (updateMessTimer >= UpdateMessageTimeSpan)
        {
            massText.text = rigidbody2D.mass.ToString();
            speedZText.text = rigidbody2D.velocity.x.ToString(floatFormat1);
            speedYText.text = rigidbody2D.velocity.y.ToString(floatFormat1);
            currentTypeText.text = TypeText[(int)buc.BallType];
        }
    }
}
